﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Jumpton.Persistent;
using Jumpton.SFA.Server.Entity;

namespace Jumpton.SFA.Server.BusinessRule.MasterData
{
    public class WareHouseFromProductManager:BusinessLogic
    {
        public PRODUCT_SHIP_FROM Load(int id)
        {
            return (PRODUCT_SHIP_FROM)ObjectRow.Load(typeof(PRODUCT_SHIP_FROM), string.Format("this.ID={0}", id));
        }
        public PRODUCT_SHIP_FROM Load(decimal id)
        {
            return (PRODUCT_SHIP_FROM)ObjectRow.Load(typeof(PRODUCT_SHIP_FROM), string.Format("this.ID={0}", id));
        }
        public PRODUCT_SHIP_FROM LoadID(int Code)
        {
            return (PRODUCT_SHIP_FROM)ObjectRow.Load(typeof(PRODUCT_SHIP_FROM), string.Format("this.ProductID={0}", Code));
        }
        
        public PRODUCT_SHIP_FROM LoadShipFrom(string ShipFrom)
        {
            return (PRODUCT_SHIP_FROM)ObjectRow.Load(typeof(PRODUCT_SHIP_FROM), string.Format("this.SHIPFROMCODE={0}", ShipFrom)); 
        }

        /// <summary>
        /// 获取仓库产品信息
        /// </summary>
        /// <param name="warehouseCode">仓库ID</param>
        /// <param name="domainid">域ID</param>
        /// <returns></returns>
        public ObjectTable GetProdcutShipFromTable(string warehouseCode,decimal domainid)
        {
            StringBuilder sb = new StringBuilder();

            if (warehouseCode != null && warehouseCode.Length > 0)
            {
                sb.AppendFormat("this.SHIPFROMCODE='{0}'", warehouseCode);
            }
            if (domainid > 0)
            {
                sb.AppendFormat("and this.DOMAINID='{0}'", domainid);
            }

            return null;
        }



        public bool Save(PRODUCT_SHIP_FROM productfrom)
        {
            try
            {
                productfrom.Save();
                
                return true;
            }
            catch (Exception ex)
            {
                this.message = ex.Message;
                throw ex;
            }
        }
        public bool Delete(PRODUCT_SHIP_FROM productfrom)
        {
            try
            {
                if(productfrom!=null&&productfrom.ID!=0)
                    productfrom.Delete();

                return true;
            }
            catch (Exception ex)
            {
                this.message = ex.Message;
                throw ex;
            }
        }
    }
}
